package com.simu.towercrane.myactivty;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVMobilePhoneVerifyCallback;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.RequestMobileCodeCallback;
import com.simu.own.utils.T;
import com.simu.towercrane.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MsgVerificationActivity extends Activity implements OnClickListener{

	EditText mTelET=null;
	EditText mVerificationET=null;
	Button mAgainBtn=null;
	Button mCommitBtn=null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_msg_verification);
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		mTelET=(EditText) findViewById(R.id.username);
		mVerificationET=(EditText) findViewById(R.id.verification);
		mAgainBtn=(Button) findViewById(R.id.again);
		mCommitBtn=(Button) findViewById(R.id.commit);
		mTelET.setOnClickListener(this);
		mVerificationET.setOnClickListener(this);
		mAgainBtn.setOnClickListener(this);
		mCommitBtn.setOnClickListener(this);
		String userName=getIntent().getStringExtra("userName")+"";
		mTelET.setText(userName);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		//重新发送验证码
		case R.id.again:
			  String telString=(mTelET.getText()+"").trim();
		      AVUser.requestMobilePhoneVerifyInBackground(telString,new RequestMobileCodeCallback() {

		          @Override
		          public void done(AVException e) {
		            //发送了验证码以后做点什么呢		 
		        	  if(e==null){
		        	  T.s(getApplicationContext(), "短信发送成功");
		        	  }else{
		        		  T.s(getApplicationContext(), e.getMessage());
		        	  }
		          }
		        });	
			break;
	    //提交验证码
		case R.id.commit:			
			String verificationStr=(mVerificationET.getText()+"").trim();
			AVUser.verifyMobilePhoneInBackground(verificationStr, new AVMobilePhoneVerifyCallback() {

			      @Override
			      public void done(AVException e) {
			        // TODO Auto-generated method stub			    	
			    	  if(e==null){
			        	  T.s(getApplicationContext(), "验证成功");
			        	  finish();
			        	  }else{
			        		  T.s(getApplicationContext(), e.getMessage());
			        	  }
			      }
			    });
			break;
		default:
			break;
		}
	}
	

	public void back(View view) {
		finish();
	}
}
